 /**
   * Copyright 2014 Viettel Telecom. All rights reserved.
   * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
   */
 package com.viettel.core.dao.cms; 
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.viettel.core.entities.cms.ExpertGroup;
import com.viettel.core.enumtype.ExpertGroupStatus;
import com.viettel.core.exceptions.DataAccessException;
import com.viettel.core.repo.IRepository;
 /**
   *  Mo ta muc dich cua lop (interface)
   *  @author: HUYNHDC
   *  @version:  
   *  @since: 24/06/2014 - 10:50:59
   */
 	public class ExpertGroupDAOImpl implements ExpertGroupDAO { 
 		private IRepository repo; 
 		
 	 	public void setRepo(IRepository repo) {
 			this.repo = repo;
 		} 
 
	 /**
	   * 
	   *  @author: HUYNHDC
	   *  @version:  
	   *  @since: 24/06/2014 - 10:50:59
	   */
 	@Override 
	public ExpertGroup getExpertGroupById(Integer id) throws DataAccessException { 
		return repo.getEntityById(ExpertGroup.class, id); 
	} 
 	 /**
	   *  
	   *  @author: HUYNHDC
	   *  @version:  
	   *  @since: 24/06/2014 - 10:50:59
	   */
	@Override 
	public ExpertGroup getExpertGroupByCmsUserId(Integer id) throws DataAccessException { 
		List<Object> params = new ArrayList<Object>();
		String sql = "SELECT * FROM EXPERT_GROUP  where CMS_USERS_ID = ?";
		params.add(id);
		return repo.getEntityBySQL(ExpertGroup.class, sql, params);
	} 
	/**
	   *  @author: HUYNHDC
	   *  @version:  
	   *  @since: 24/06/2014 - 10:50:59
	   */
	@Override 
	public List<ExpertGroup> lstExpertGroupByCmsUserId(Integer id) throws DataAccessException { 
		List<Object> params = new ArrayList<Object>();
		String sql = "SELECT * FROM EXPERT_GROUP  where STATUS != ? AND CMS_USERS_ID = ?";
		params.add(ExpertGroupStatus.DELETED.getValue());
		params.add(id);
		return repo.getListBySQL(ExpertGroup.class, sql, params);
	} 
	/**
	   *  @author: HUYNHDC
	   *  @version:  
	   *  @since: 24/06/2014 - 10:50:59
	   */
	@Override 
	public List<ExpertGroup> lstExpertGroupByGroupId(Integer id) throws DataAccessException { 
		List<Object> params = new ArrayList<Object>();
		String sql = "SELECT * FROM EXPERT_GROUP  where STATUS != ? AND GROUP_CATEGORY_ID = ?";
		params.add(ExpertGroupStatus.DELETED.getValue());
		params.add(id);
		return repo.getListBySQL(ExpertGroup.class, sql, params);
	} 
 	 /**
 	   *  @author: HUYNHDC
 	   *  @version:  
 	   *  @since: 24/06/2014 - 10:50:59
 	   */
 	@Override 
	public ExpertGroup createExpertGroup(ExpertGroup expertGroup) 
			throws DataAccessException { 
		if (expertGroup == null) { 
			throw new IllegalArgumentException("expertgroup"); 
		} 
		repo.create(expertGroup); 
		return repo.getEntityById(ExpertGroup.class, expertGroup.getId()); 
	} 
 	 /**
 	   * 
 	   *  @author: HUYNHDC
 	   *  @version:  
 	   *  @since: 24/06/2014 - 10:50:59
 	   */
 	@Override 
	public void updateExpertGroup(ExpertGroup expertGroup) throws DataAccessException { 
		if (expertGroup == null) { 
			throw new IllegalArgumentException("expertgroup"); 
		} 
		repo.update(expertGroup); 
	} 
 	 /**
 	   *  
 	   *  @author: HUYNHDC
 	   *  @version:  
 	   *  @since: 24/06/2014 - 10:50:59
 	   */
 	@Override 
	public void deleteExpertGroup(ExpertGroup expertGroup) throws DataAccessException { 
		if (expertGroup == null) { 
			throw new IllegalArgumentException("expertgroup"); 
		} 
		repo.delete(expertGroup); 
	}

 	 /**
	   * 
	   *  @author: HUYNHDC
	   *  @version:  
	   *  @since: 24/06/2014 - 10:50:59
	   */
	@Override 
	public void deleteExpertGroupByCmsUserId(Integer id) throws DataAccessException { 
		List<Object> params = new ArrayList<Object>();
		String sql = "UPDATE EXPERT_GROUP SET status = ? WHERE cms_users_id = ?";
		params.add(ExpertGroupStatus.DELETED.getValue());
		params.add(id);
		repo.executeSQLQuery(sql, params);
	} 

} 
 
